import Vue from 'vue'
import App from './App.vue'
import ViewUI from 'view-design';
import axios from 'axios';

import DataSet from '@antv/data-set';

import 'view-design/dist/styles/iview.css';
import router from './router';
import store from './store';
import './rem';
import './assets/common.css'
import urls from './common'

Vue.prototype.$http=axios;
Vue.prototype.dealThing=0;
Vue.prototype.urls=urls;
Vue.prototype.DataSet=DataSet;
Vue.prototype.settimes='';
Vue.config.productionTip = false;
Vue.use(ViewUI);

import {Spin} from 'view-design';

Vue.prototype.needDeal=function(){
  axios.get('/api'+this.urls.getTodoCaseCount).then((result)=>{
      if(result.data.code===200){
        // this.dealThing=result.data.data.count
        this.$store.commit('dealThing', result.data.data.count)
      }else{
        this.$Message.warning('网络错误');
      }
  })
};

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

new Vue({
  router,
  store,
  render: h =>h(App),
  watch:{
    $route(to,from){
      if(localStorage.getItem('username')){
        if(localStorage.getItem('roleid')=='arbSecretary'
           &&to.path.indexOf('commissioner')<0){
            this.$router.push('/');
        }else if(localStorage.getItem('roleid')=='arbDirector'
           &&to.path.indexOf('director')<0){
            this.$router.push('/');
        }else if(localStorage.getItem('roleid')=='arbPerson'
           &&to.path.indexOf('bitrator')<0){
            this.$router.push('/');
        }
      }else{
        if(this.$route.name=='arbitLogin'){
          return false;
        }
        this.$router.push('/');
      }
    }
  },
  created(){
    if(localStorage.getItem('username')){
      if(localStorage.getItem('roleid')=='arbSecretary'
          &&this.$route.path.indexOf('commissioner')<0){
          this.$router.push('/');
      }else if(localStorage.getItem('roleid')=='arbDirector'
          &&this.$route.path.indexOf('director')<0){
          this.$router.push('/');
      }else if(localStorage.getItem('roleid')=='arbPerson'
          &&this.$route.path.indexOf('bitrator')<0){
          this.$router.push('/');
      }
    }else{
      if(this.$route.name=='arbitLogin'){
         return false;
      }
        this.$router.push('/');    
    }
  }
}).$mount('#app')
